package com.joolun.mall;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.*;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {
        List<A> list = new ArrayList<>();
        list.add(new A(1,"a","aa"));
        list.add(new A(2,"d","dd"));
        list.add(new A(3,"c","cc"));
        list.add(new A(4,"d","dd"));
        list.add(new A(5,"c","cc"));
        list.add(new A(6,"e","ee"));

        Map<String, List<A>> listMap = list.stream().collect(Collectors.groupingBy(A::getClazz, LinkedHashMap::new ,Collectors.toList()));

        listMap.forEach((k,v)->{
            System.out.println(JSONUtil.toJsonStr(v));
        });
    }
}


@Data
@AllArgsConstructor
class A {
    private Integer id;
    private String name;
    private String clazz;
}
